package com.panghl.task;

import com.panghl.entity.OrderInfo;
import com.panghl.enums.PayType;
import com.panghl.service.OrderInfoService;
import com.panghl.service.WxPayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;


@Slf4j
@Component
public class WxPayTask {



    @Resource
    private OrderInfoService orderInfoService;

    @Resource
    private WxPayService wxPayService;

    /**
     * 从第0秒开始每隔30秒执行一次，查询创建超过5分钟，并且未支付的订单
     */
    @Scheduled(cron = "1/30 * * * * ?")
    public void orderConfirm() throws IOException {
        log.info("orderConfirm 被執行....");

        List<OrderInfo> orderInfoList = orderInfoService.getNoPayOrderByDuration(5,PayType.WXPAY.getType());
        for (OrderInfo orderInfo : orderInfoList) {
            String orderNo = orderInfo.getOrderNo();
            log.warn("超时订单====> {}",orderNo);

            //核实订单状态，调用支付宝支付查单接口
            wxPayService.checkOrderStatus(orderNo);
        }
    }




}
